<%@ page contentType="text/html; charset=UTF-8"%>
<%@ include file="/jsp/common/common.jsp"%>
<%
	String flag = (String) request.getParameter("flag");
%>
<html>
    <head>
        <title><%=IConstant.PROGRAEM_TITLE%></title>
        <script language="javascript">
		
        	var chkOrganId = "";
        	var chkOrganName = "";
			Ext.onReady(function(){

		    	var flag = "<%=flag%>";
	
				var storeSQ = new Ext.data.Store({
        			proxy:new Ext.data.HttpProxy({url:'organ!getOrgan.do'}),
        			reader:new Ext.data.JsonReader({},['id','text','qtip','parentId']),
        			autoLoad:true,
        			listeners:{"load":function(store,records){
        							if (records != null && records != "") {
										for (var i=0; i<records.length; i++){
	       									var n = new Ext.tree.TreeNode({
                								id:records[i].data.id,
                								text:records[i].data.text,
                								qtip:records[i].data.qtip,
                								leaf:true
											});
	       									// 第一层菜单时
	       									if (records[i].data.parentId == "0") {
            									tree.root.appendChild(n);
            								// 下级菜单
	       									} else {
	       										tree.getNodeById(records[i].data.parentId).leaf = false;
	       										tree.getNodeById(records[i].data.parentId).appendChild(n);
	       									}
   										}
   										
   										 tree.root.expandChildNodes();
   										
   										// 循环完了查询全部
   										if (tree.root.firstChild != undefined) {
   											try {
   												parent.window.frames["mainFrom"].document.frmM.elements["searchBean.con1"].value = tree.root.firstChild.attributes.qtip;
	        									parent.window.frames["mainFrom"].cmt();
	        								} catch (e) {
	        								
	        								}
   										}
									} 
                    			}}
    			});

            
				/* 生成Ttee,放到tree Div里面 */
 				var tree = new Ext.tree.TreePanel({
                        id:"mytree",
                        rootVisible:false,
                        root : new Ext.tree.TreeNode({   
                    			id : "root", 
                    			draggable:false, 
                    			singleClickExpand:true, 
                    			text : "<%=IConstant.PROGRAEM_TITLE%>"
	 						}),  
                        store : storeSQ,
				        useArrows:true,
				        autoScroll:true,
				        animate:true,
				        containerScroll:true,
				        listeners:{"click":function(node){ 
													// 查询
													if (flag == "left") {
														if (node.id != '1') {
															chkOrganId = node.id;
        													chkOrganName = node.text;
        												} else {
        													chkOrganId = '';
        													chkOrganName = '';
        												}
														if (parent.window.frames["mainFrom"] != undefined) {
															//window.alert(node.id);
													    	parent.window.frames["mainFrom"].document.frmM.elements["searchBean.con1"].value = node.attributes.qtip;
													    	parent.window.frames["mainFrom"].document.frmM.elements["searchBean.con2"].value = "";
													    	parent.window.frames["mainFrom"].document.frmM.elements["searchBean.con3"].value = "";
													    	//parent.window.frames["mainFrom"].document.frmM.elements["organcid"].value = node.id;
													    	parent.window.frames["mainFrom"].cmt();
	        											}
													} else {
														// 参照
														window.opener.document.frmM.elements["user.organ.id"].value = node.id;
														window.opener.document.frmM.elements["organName"].value = node.text;
														window.close();	
													}
                    	}}
					});
					
	            	var layout = new Ext.Viewport({   
	                				layout: 'border',   
	                				margins:'5 0 5 5',   
	               		 			items: [ { region: 'center',   
	                    			title: '机构选择',
	                    			layout:'fit',
	                    			items:[tree]  
	                }]   
	            }); 
 			});      

		</script>
	</head>
	<body>
	</body>
</html>
